package test5.lupeng.jf.com.teamdemo.adapter;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import test5.lupeng.jf.com.teamdemo.R;
import test5.lupeng.jf.com.teamdemo.bean.response.ResponseFans;
import test5.lupeng.jf.com.teamdemo.untils.GlideCircleTransform;

//粉丝列表的适配器
public class FansAdapter extends RecyclerView.Adapter{

    ArrayList<ResponseFans.ResultsBean> results;

    public FansAdapter(ArrayList<ResponseFans.ResultsBean> results) {
        this.results = results;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_guanzhu, null);
        FansViewHolder holder = new FansViewHolder(view);
        return holder;
    }

    public class FansViewHolder extends RecyclerView.ViewHolder{

        private final ImageView headImage;
        private final TextView userName;
        private final TextView address;

        public FansViewHolder(View itemView) {
            super(itemView);

            headImage = itemView.findViewById(R.id.headImage);
            userName = itemView.findViewById(R.id.userName);
            address = itemView.findViewById(R.id.address);
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        FansViewHolder holder1 = (FansViewHolder) holder;
        ResponseFans.ResultsBean  bean = results.get(position);
        Glide.with(holder1.itemView.getContext())
                .load(bean.getFollower().getHeadProtrait())
                .transform(new GlideCircleTransform(holder1.itemView.getContext()))
                .into(holder1.headImage);

        holder1.userName.setText(bean.getFollower().getUsername());
        holder1.address.setText(bean.getFollower().getAddress());

    }

    @Override
    public int getItemCount() {
        return results.size();
    }
}
